/*
  ******************************************************************************
  * @file    main.c
  * @brief   main source File.
  ******************************************************************************
*/
#include "APP.h"
#include "FreeRTOS.h"
#include "task.h"

UART_HandleTypeDef Uart2_Handle;

/************************************************************************
 * function   : Uart_Init
 * Description: Uart Initiation. 
 ************************************************************************/ 
void Uart_Init(uint32_t fu32_Baudrate)
{
    Uart2_Handle.Instance = UART2;
    Uart2_Handle.Init.BaudRate   = fu32_Baudrate;
    Uart2_Handle.Init.WordLength = UART_WORDLENGTH_8B;
    Uart2_Handle.Init.StopBits   = UART_STOPBITS_1;
    Uart2_Handle.Init.Parity     = UART_PARITY_NONE;
    Uart2_Handle.Init.Mode       = UART_MODE_TX_RX_DEBUG;
    Uart2_Handle.Init.HwFlowCtl  = UART_HWCONTROL_NONE;

    HAL_UART_Init(&Uart2_Handle);
	
    /* UART_DEBUG_ENABLE control printfS */   
    //printfS("MCU is running, HCLK=%dHz, PCLK=%dHz\n", System_Get_SystemClock(), System_Get_APBClock());
}

void led_init(void)
{
	GPIO_InitTypeDef GPIOF_Handle;
	
	GPIOF_Handle.Pin       = GPIO_PIN_3;
	GPIOF_Handle.Mode      = GPIO_MODE_OUTPUT_PP;
	GPIOF_Handle.Pull      = GPIO_PULLUP;
	GPIOF_Handle.Alternate = GPIO_FUNCTION_0;

	HAL_GPIO_Init(GPIOF, &GPIOF_Handle);
}

TaskHandle_t LED1Task_Handler;
TaskHandle_t LED2Task_Handler;

void led1_task(void *pvParameters)
{
    while(1)
    {
      printfS("LED1\r\n");
      vTaskDelay(1000);
    }
}


void led2_task(void *pvParameters)
{
    while(1)
    {
      printfS("LED2\r\n");
      vTaskDelay(1000);
    }
}

/*********************************************************************************
* Function    : main
* Description : The application entry point.
* Input       : None
* Output      : None
**********************************************************************************/
int main(void)
{
	System_Init();

	Uart_Init(115200); // UART2: PA2 PA3

	/* GPIO_OUTPUT、GPIO_INT、GPIO_PC13、LED_BLINK */
	//APP_GPIO_Test(LED_BLINK);
    
	xTaskCreate(led1_task,   "led1_task",   128,  NULL, 2, &LED1Task_Handler);  
	xTaskCreate(led2_task,   "led2_task",   128,  NULL, 3, &LED2Task_Handler);  
	vTaskStartScheduler();

	while(1)
	{

	}
}

